package com.yay.mashiro.yayclient.ui.clickgui.controls;

import java.awt.Color;

import org.lwjgl.input.Mouse;

import com.yay.mashiro.yayclient.Yay;
import com.yay.mashiro.yayclient.module.Value;
import com.yay.mashiro.yayclient.module.modules.render.ClickGui;
import com.yay.mashiro.yayclient.ui.clickgui.font.UnicodeFontRenderer;
import com.yay.mashiro.yayclient.ui.clickgui.panel.WindowPanel;
import com.yay.mashiro.yayclient.utils.Colors;
import com.yay.mashiro.yayclient.utils.PlayerUtils;

import ClassSub.Class246;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;

public class Slider {
	Value<Double> value;
    public float x;
    public float y;
    private boolean isDraging;
    private boolean clickNotDraging;
    public int tX;
    public int tY;
    public int dragX;
    public int dragY;
    double ani;

    public Slider(Value value) {
        this.value = value;
    }

    public void draw(float f, float f2) {
    	
        this.x = f;
        this.y = f2;
        UnicodeFontRenderer unicodeFontRenderer = Yay.getFontManager().comfortaa16;
        double d = (this.value.getValueState() - this.value.getValueMin()) / (this.value.getValueMax() - this.value.getValueMin());
        
        unicodeFontRenderer.drawString(this.value.getValueName().split("_")[1], f + 120.0f, f2, new Color(212, 212, 212).getRGB());
        unicodeFontRenderer.drawString(this.value.getValueState() + "", f - 165.0f - (float)unicodeFontRenderer.getStringWidth(this.value.getValueState() + ""), f2, ClickGui.theme.isCurrentMode("Light") ? Colors.GREY.c : new Color(212, 212, 212).getRGB());
        
//        System.err.println(WindowPanel.isDraging);
//        if (this.ani == 0.0 || WindowPanel.isDraging) {
        	
            this.ani = (float)((double)(f - 15.0f) - (140.0 - 140.0 * d));
//        }
        this.ani = Class246.getAnimationState(this.ani, (float)((double)(f - 15.0f) - (140.0 - 140.0 * d)), 600.0);
        Class246.drawRoundedRect(f - 155.0f, f2 + 3.0f, f - 15.0f, f2 + 6.0f, 1.0f, ClickGui.theme.isCurrentMode("Light") ? Colors.GREY.c : new Color(27, 27, 27).getRGB());
        Class246.drawRoundedRect(f - 155.0f, f2 + 3.0f, (float)this.ani, f2 + 6.0f, 1.0f, ClickGui.theme.isCurrentMode("Light") ? new Color(-14848033).brighter().getRGB() : new Color(16, 72, 182).getRGB());
        Class246.circle((float)this.ani, f2 + 4.5f, 3.0f, ClickGui.theme.isCurrentMode("Light") ? new Color(-14848033).brighter().getRGB() : new Color(29, 111, 223).getRGB());
    }

    public void onPress(int n, int n2) {
        ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft());
        if (Mouse.isButtonDown((int)0)) {
            if (this.isHovering(n, n2, this.x - 155.0f, this.y - 3.0f, this.x - 15.0f, this.y + 10.0f) || this.isDraging) {
                this.isDraging = true;
            } else {
                this.clickNotDraging = true;
            }
            if (this.isDraging && !this.clickNotDraging) {
                double d = ((float)n - this.x + 155.0f) / 140.0f;
                if (d < 0.0) {
                    d = 0.0;
                }
                if (d > 1.0) {
                    d = 1.0;
                }
                double d2 = (this.value.getValueMax() - this.value.getValueMin()) * d + this.value.getValueMin();
                d2 = (double)Math.round(d2 * (1.0 / this.value.getSteps())) / (1.0 / this.value.getSteps());
                this.value.setValueState(d2);
            }
        } else {
            this.isDraging = false;
            this.clickNotDraging = false;
        }
        this.tX = n;
        this.tY = n2;
    }

    private boolean isHovering(int n, int n2, double d, double d2, double d3, double d4) {
        return ((double)n > d && (double)n < d3 && (double)n2 > d2 && (double)n2 < d4 ? 1 : 0) != 0;
    }
}
